package com.zhj.leetcode;

/**
 * 力扣 121 买卖股票问题
 */
public class Test121 {

    public static void main(String[] args) {
        int[] prices = {1, 7, 5, 3, 0, 9};
        System.out.println(maxProfit(prices));
    }

    public static int maxProfit(int[] prices) {
        if (prices == null || prices.length == 0) return 0;
        int max = 0;
        int min = prices[0];
        for (int i : prices) {
            max = Math.max(max, i - min);
            min = Math.min(min, i);
        }
        return max;
    }
}
